﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SpaceSquirrel.SpecialLevelStuff
{
	public class BikeLevelStuff : SpecialLevel
	{
		private List<double[]> particles = new List<double[]>();
		private int counter = 0;

		public BikeLevelStuff(PlayScene scene)
			: base(scene)
		{
			this.HasUpdate = true;
			this.HasRender = true;
		}

		public override void Update()
		{
			if (this.counter == 0)
			{
				this.scene.Sprites.Add(new Sprite("bird2", 16, 48));
			}

			this.counter++;
			PlayScene scene = this.scene;
			Sprite player = scene.Player;
			if (player.x > (scene.cols - 1) * 16) // one less because you can't technically go off screen
			{
				scene.Next = new VictorySequenceScene(scene);
			}

			if (this.counter % 2 == 0)
			{
				double[] pt = new double[] {
					player.x,
					player.y,
					TuxedoLib.Util.RandomDouble() * 16 - 8,
					TuxedoLib.Util.RandomDouble() * 6 - 5
				};

				this.particles.Add(pt);
			}

			foreach (double[] pt in this.particles)
			{
				pt[0] += pt[2];
				pt[1] += pt[3];
				pt[3] += 2;
			}
		}

		public override void Render(TuxedoLib.Image screen, int offsetX, int offsetY, int renderCounter)
		{
			Sprite p = this.scene.Player;
			int px = p.x + offsetX;
			int py = p.y + offsetY;

			foreach (double[] pt in this.particles)
			{
				TuxedoLib.Draw.RectangleFill(screen, TuxedoLib.Draw.CreateColor(255, 255, 128), (int)pt[0] + offsetX, (int)pt[1] + offsetY, 3, 3);
			}

			if (this.particles.Count > 40)
			{
				this.particles.RemoveAt(0);
			}
		}
	}
}
